/*

 $Id: nvclib.h 5 2009-10-09 02:20:19Z alex.mobilebi $
 $Date: 2009-10-09 02:20:19 +0000 (Fri, 09 Oct 2009) $
 $Author: alex.mobilebi $
 $Revision: 5 $

 Copyright(C) 2009 Alex Lee(alex@mobilebi.com)

 */

#ifndef NVC_LIB_H
#define NVC_LIB_H


#define MAX_BOARD_NUM 4
#define MAX_PORT_NUM 16
#define MAX_TS_NUM 128
#define MAX_CHANNEL_NUM 256
#define MAX_LINK_NUM 1024
#define BLOCKS_PER_CHANNEL 4
#define CRC_MODE 0x01 //16 bit CRC
#define PORT_TYPE_E1 0x00
#define PORT_TYPE_T1 0x01
#define PORT_SYNC_MODE_T1 0x00
#define PORT_SYNC_MODE_E1 0x01
#define PORT_SYNC_MODE_4M 0x02
#define PORT_SYNC_MODE_8M 0x03
#define CODE_TYPE_NOHDB3 0x00
#define CODE_TYPE_HDB3 0x01
#define FRAME_TYPE_DF 0x00
#define FRAME_TYPE_CRC4 0x01
#define PORT_IMP_MODE_75 0x00
#define PORT_IMP_MODE_100 0x01
#define PORT_IMP_MODE_110 0x02
#define PORT_IMP_MODE_120 0x03

#define ENODEVICE 0x100    //no any devices in system
#define ENOCONFIG 0x101    //the ports or links not be configured
#define ENOTOPEN  0x102    //can't open device file
#define ENOFILE   0x103    //file not exists
#define EINVALPARA 0x104   //invalid parameter
#define ENOTINIT 0x105     //not initialize
#define EINVALPORT 0x106   //invalid port configuration
#define EINVALLINK 0x107   //invalid link configuraion
#define ENODATA 0x108      //not recevie any data from card
#define ENOTRANSMIT 0x109  //not transmit any data to card
#define ETIMEOVER 0x10A
#define ENOCONNECT 0x10B
//driver error
#define ENOBUF   0x110     //buffer is overflow
#define ETPQFULL 0x111     //transmit pending queue is full
#define ERFQFULL 0x112     //receive free queue is full
#define ERFQOVER 0x113     //receive free queue is overflow

//log level 
#define DEBU 0x03
#define INFO 0x02
#define WARN 0x01
#define ERRO 0x00

#define PACKET_TYPE_DISCARD         0x00
#define PACKET_TYPE_DATA            0x01
#define PACKET_TYPE_STATUS          0x02

struct port_config
{
	unsigned char board_id;
	unsigned char port_id;
	unsigned char port_type;
	unsigned char port_mode;
	unsigned char frame_type;
	unsigned char code_type;
	unsigned char impedance;
};
struct link_config
{
	unsigned short link_id;
	unsigned char board_id;
	unsigned char port_id;
	unsigned char link_type;
	unsigned char start_ts;
	unsigned char ts_num;
};

int set_port_config(const struct port_config conf);
int set_link_config(const struct link_config conf);
int start(void);
int receive(unsigned char * buff, const unsigned int length);
int transmit(unsigned int * buff, const int size);
void stop(void);
void init_config_data_struct(void);
void write_log(char * msg, unsigned char level);
void set_logfile_name(char * filename);
void set_log_level(const unsigned char level);
void set_dump_option(char dump_option);
void dump_regs (char *filename, char dev);


#endif/*NVC_LIB_H*/